package day07;

import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Demo04 {

	public static void main(String[] args) throws Exception {
		String filename="abc/emp.dat";
		RandomAccessFile raf=new RandomAccessFile(filename,"rw");
		
		Date date=new Date();
		
		write(raf,0,"Tom",23,"男",100,date);
		write(raf,1,"高德",10,"男",1000,date);
		
		
		raf.close();
		
		
		
		

	}

	public static void write(RandomAccessFile raf,int n, String name,
			int age,String gender, int salary, Date hiredate) throws Exception {

		SimpleDateFormat fmt=new SimpleDateFormat("yyyy-MM-dd");
		
		int start=n*80;
		raf.seek(start);
		
		byte[]bytes=name.getBytes("UTF-8");
		raf.write(bytes);
		
		raf.seek(start+32);
		raf.writeInt(age);
		
		raf.seek(start+32+4);
		bytes=gender.getBytes("UTF-8");
		raf.write(bytes);
		
		raf.seek(start+32+4+10);
		raf.writeInt(salary);
		
		String date=fmt.format(hiredate);
		bytes=date.getBytes("UTF-8");
		raf.write(bytes);
		
		
		
		
	}

}
